//
//  YDYTabBar.m
//  DYSisterAPP
//
//  Created by 杨德勇 on 16/7/26.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYTabBar.h"

@interface YDYTabBar()
@property (nonatomic, weak) UIButton *poseBtn;
@end

@implementation YDYTabBar


#pragma mark -
#pragma mark -init的时候设置bar的背景图片
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
    }
    return self;
}


-(void)layoutSublayersOfLayer:(CALayer *)layer{
    
    [super layoutSublayersOfLayer:layer];
    
    
    CGFloat btnY = 0;
    CGFloat btnW = self.bounds.size.width / 5;
    CGFloat btnH = self.bounds.size.height;
    int i = 0;
    
    
    
    for (UIView *subview in self.subviews) {
        
    if (subview.class  != NSClassFromString(@"UITabBarButton")) continue;
        
        CGFloat btnX = i * btnW;
        if (i >= 2) {
            btnX += btnW;
        }
        subview.frame = CGRectMake(btnX, btnY, btnW, btnH);
        i ++;
    }
    self.poseBtn.frame = CGRectMake(0, 0, btnW, btnH);
    self.poseBtn.center = CGPointMake(self.frame.size.width * 0.5, btnH * 0.5);
    self.poseBtn.contentEdgeInsets = UIEdgeInsetsMake(0 , 0, 0, 0);
    
    
}

-(UIButton *)poseBtn{
    if (!_poseBtn) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        btn.backgroundColor = YDYRandomColor;
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        
        [btn addTarget:self action:@selector(postBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
        
            [self addSubview:btn];
            _poseBtn = btn;
        
        

    }
    return _poseBtn;
}

-(void)postBtnDidClick{
    YDYLog(@"aa");
}

@end
